<template>
  <div class="content">
    <textarea
      v-model="content"
      name="content"
      @change="loseFocus"
      required
    ></textarea>
    <span>内容</span>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";

@Component({
  components: {},
})
export default class ContentInput extends Vue {
  content = "";

  loseFocus(): void {
    console.log(this.content);
  }
}
</script>

<style lang="scss" scoped>
.content {
  width: 70%;
  position: relative;

  textarea {
    width: 90%;
    height: 6vh;
    padding: 10px;
    border: 1px solid lightgray;
    border-radius: 5px;
    outline: none;
    font-size: 1em;
    transition: 0.5s;

    &:focus {
      border: 1px solid aquamarine;
    }

    &:valid ~ span,
    &:focus ~ span {
      transform: translateX(10px) translateY(-10px);
      font-size: 0.8em;
      padding: 0 10px;
      background-color: #fff;
      border-left: 1px solid black;
      border-right: 1px solid black;
    }
  }

  span {
    position: absolute;
    left: 0;
    top: 0;
    padding: 10px;
    font-size: 1em;
    pointer-events: none;
    transition: 0.5s;
  }
}
</style>
